|
|
|
| Table 4.3. continued | | Control | Property | Setting | | Command Button | Name | cmdExit | | Caption | E&xit | | FontBold | False | | Height | 300 | | Width | 1200 |
|
|
|
|
|
|
Save the form as COLORS.FRM and the project as COLORS.VBP. You have built a form that has three command buttons: Default, System, and Custom. You'll add code to the project that makes each of these buttons change the color scheme of the form. First, you'll add the code that sets the colors to the Win95 default: light gray. |
|
|
|
|
|
|
|
|
First, create a Visual Basic constant to represent the hex value for light gray, white, and black. Here's the code: |
|
|
|
|
|
|
|
|
Option Explicit
'
' constant for colors
Const LIGHT_GRAY = &HC0C0C0
Const WHITE = &HFFFFFF
Const BLACK = &H0 |
|
|
|
|
|
|
|
|
Next, add a new procedure, SetColors, that sets the colors of the form. Because you'll be using this code to set more than one color scheme, add a parameter called nSet to the procedure header. You only have one set right now, but you'll add others soon. The following code sets the BackColor property of the form and data control to light gray: |
|
|
|
|
|
|
|
|
Sub SetColors (nSet As Integer)
'
' set to default colors
If nSet = 0 Then
pnlDisplayOnly.BackColor = LIGHT_GRAY
pnlPalette.BackColor = LIGHT_GRAY
frmColor.BackColor = LIGHT_GRAY
Data1.BackColor = LIGHT_GRAY
'
txtOneLine.BackColor = WHITE
txtOneLine.ForeColor = BLACK
End If
End Sub |
|
|
|
|
|